package com.whd.demo;

/**
 * @author whd
 * @date 2023/07/26 19:08:59
 */
public class Demo3 {

    private static Integer count = 100;

    public static void main(String[] args) {
        //4个窗口，卖100张票。

                for (int i = 0; i < 4; i++) {
                    Thread th = new Thread(()->{
                        while (count>=0) {
                            synchronized (count){
                            count--;
                            }
                            if (count < 0) {
                                System.out.println(Thread.currentThread().getName() +"售票结束");
                                return;
                            }
                            System.out.println(Thread.currentThread().getName() + "号窗户售出一张票，" + "剩余" + count + "张票");
                        }
                        });
                    th.start();
                }
    }
}
